import { useModel, useParams } from '@umijs/max'
import { Spin } from 'antd'
import './AppletMiddlePage.less'
import { useEffect } from 'react'

function AppletMiddlePage() {
  const { token } = useParams()
  const { GetLongUrl } = useModel('AppletMiddlePage')

  useEffect(() => {
    !isWeChat() && handleJump()
  }, [token])

  // 判断当前是否是微信
  const isWeChat = () => {
    let currentIsWeChat = navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1
    return currentIsWeChat
  }

  // 页面跳转
  const handleJump = async () => {
    const res = await GetLongUrl({ code: token })
    if (res) {
      window.location.href = res.page_url
    }
  }

  return (
    <div className='applet_middle_page'>
      {isWeChat() ? (
        <img src='https://qny.weizulin.cn/images/202404291018872.jpg' />
      ) : (
        <>
          <Spin></Spin>
          <p>页面加载中...</p>
        </>
      )}
    </div>
  )
}

export default AppletMiddlePage
